package edu.zut.cs.software.perfect.teacher.web.spring.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.process.domain.CourseProcess;
import edu.zut.cs.software.perfect.teacher.domain.Department;
import edu.zut.cs.software.perfect.teacher.service.DepartmentManager;

/**
 * @ClassName DepartmentController
 * @Description TODO
 * @Author lixianglong
 * @Date 2020年5月30日 上午12:25:46
 * @Version 1.0
 */
@ResponseBody
@Controller
@RequestMapping("/teacher/department")
public class DepartmentController extends GenericController<Department,Long,DepartmentManager>{
	DepartmentManager departmentManager;
	
	
	
	@Autowired
	public void setDepartmentManager(DepartmentManager departmentManager) {
		this.departmentManager = departmentManager;
		this.manager=this.departmentManager;
	}
	@ResponseBody
    @GetMapping(value = "findall", produces = "application/json;charset=utf-8")
	public String findAll() {
		List<Department> departmentList = this.manager.findAll();
        @SuppressWarnings({ "rawtypes", "unchecked" })
		PageInfo pageInfo = new PageInfo(departmentList);
        return JSON.toJSONString(pageInfo);
	}
	
	@GetMapping("/findbyid/{id}")
	public String findById(@PathVariable("id") Long id) {
		Optional<Department> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	

	@GetMapping("/save/{name}")

	public Department save(@PathVariable("name") String departmentName) {
		Department department= new Department();
		department.setDepartmentName(departmentName);
		Department result = departmentManager.save(department);
		return result ;
	}
	

	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {

		Boolean result = this.manager.deleteById(id);
		return result;
	}
	
	@GetMapping("/updata/{id}")

	public Department updata(@PathVariable("id") Long id) {
		Optional< Department> department = this.manager.findByCourseId(id);
		 Department department_s = department.get();
		 department_s.setDepartmentName("shuxue");
		 Department result = this.manager.save(department_s);
		return result;
	}
	
	
	
}
